/*
 * @Author: 老刘
 * @Date: 2020-04-29 15:51:38
 * @Description: 索引
 */
const app = getApp();
Page({
	data: {
		customBar: app.globalData.capsule.bottom + app.globalData.capsule.top - app.globalData.statusBarHeight,
		listCurrentId: true,
		hidden: true
	},
	onLoad () {
		let list = [];
		for (let i = 0; i < 26; i++) {
			list[i] = String.fromCharCode(65 + i);
		}
		this.setData({
			list: list,
			listCurrent: list[0]
		});
	},
	onReady () {
		let that = this;
		wx.createSelectorQuery().select('.nav-box').boundingClientRect((res) => {
			that.setData({
				boxTop: res.top
			});
		}).exec();
		wx.createSelectorQuery().select('.container').boundingClientRect((res) => {
			that.setData({
				barTop: res.top
			});
		}).exec();
	},
	// 获取文字信息
	getCurrent (e) {
		this.setData({
			hidden: false,
			listCurrent: this.data.list[e.target.id]
		});
	},
	setCurrent () {
		this.setData({
			hidden: true,
			listCurrent: this.data.listCurrent
		});
	},
	// 滑动选择Item
	touchMove (e) {
		let y = e.touches[0].clientY;
		let offsetTop = this.data.boxTop;
		let that = this;
		// 判断选择区域,只有在选择区才会生效
			if (y > offsetTop) {
			let num = parseInt((y - offsetTop) / 20);
			this.setData({
				listCurrent: that.data.list[num]
			});
		}
	},
	// 触发全部开始选择
	touchStart () {
		this.setData({
			hidden: false
		});
	},
	// 触发结束选择
	touchEnd () {
		this.setData({
			hidden: true,
			listCurrentId: this.data.listCurrent
		});
	}
});
